package aad.storyboard.model;

import java.util.HashMap;

import android.content.res.Resources;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.Log;

import utils.XLSParser;
import utils.StoryStructureParser;
import utils.XMLParser;

/*
 * Factory pattern: depending on what kind of file is being supplied by the user, a corresponding Parser (Product) will be instantiates
 */
public class StoryStructureFactory {
	
	private HashMap<Integer,StoryStructureParser> classMap = new HashMap<Integer,StoryStructureParser>();


	private Resources resources;
	private int fileId;
	private int type;
	
    public StoryStructureFactory(){
    	registerClass(0, XLSParser.getInstance());
    	registerClass(1, XMLParser.getInstance());
    }
    
   
    
    public void registerClass(int j, StoryStructureParser i){
    	classMap.put(j, i);
    }

	public void createStructure(Resources resources, int fileId) {		
		this.resources=resources;
		this.fileId=fileId;
		this.type=determineFileType(fileId);
		createStructure(type);		
	}
	
	private void createStructure(int type) {          
        	StoryStructureParser product = classMap.get(type);
        	System.out.println("Hallo"+type);
        	product.createStructure(resources, fileId);        	
	}

	private int determineFileType(int id) {
		String resource = this.resources.getString(id);		
		if(resource.endsWith("xls"))
			return XLSParser.TYPE_XLS;
		else if (resource.endsWith("xml"))
			return XLSParser.TYPE_XML;
		return -1;
	}

	
    

}
